<?php
class sectionActions extends BaseAdminActions
{
	public $section;
	public function __construct(){
		parent::__construct();
		Files::factory('Section');
		$this->section = new Section();
	}
	public function actionsIndex()
	{
		$rs = $this->section->getSection();
		$this->assign('rs', $rs);
		$this->assign('cate', $this->section->getCate());
	}
	public function actionsAdd()
	{
		if(Http::get('do')=='add'){
			$scatid = Http::post('scatid');
			$type = Http::post('type');	
			$name = Http::post('name');
			$keys =  Http::post('keys');
			$memo =  Http::post('memo');
			$nums =  Http::post('nums');
			$section =  Http::post('section');		
			
			
			$data = array(
			'scatid'=>$scatid,
			'type'=>$type,
			'name'=>$name,
			'keys'=>$keys,
			'memo'=>$memo,
			'nums'=>$nums,
			'section'=>$section,
			'dateline'=>time(),
			'upby'=>$this->user['username'],
			);			
			if($this->section->add($data)){			
				echo '添加成功！';
			}else {
				echo '添加失败！';
			}
			die();
		}
		$this->assign('section', '');
		$cate = $this->section->getCate();		
		$this->assign('cate', $cate);
	}
	public function actionsDel()
	{		
		if($this->section->del(Http::get('id')))
		{
			echo '删除成功！';
		}else{
			echo '删除失败！';
		}
		die();
	}
	public function actionsModify()
	{
		$sectionId = Http::get('id');
		if (empty($sectionId)) $this->redirect('admin/section/index');
		if (Http::get('do')=='update'){
			$scatid = Http::post('scatid');
			$type = Http::post('type');	
			$name = Http::post('name');
			$keys =  Http::post('keys');
			$memo =  Http::post('memo');
			$nums =  Http::post('nums');
			$section =  Http::post('section');		
			
			
			$data = array(
			'scatid'=>$scatid,
			'type'=>$type,
			'name'=>$name,
			'keys'=>$keys,
			'memo'=>$memo,
			'nums'=>$nums,
			'section'=>$section,
			'dateline'=>time(),
			'upby'=>$this->user['username'],
			);
			
			if($this->section->update($sectionId,$data)){			
				echo '修改成功！';
			}else {
				echo '修改失败！';
			}
			die();
		}else{
			
			$section = $this->section->getSection($sectionId);		
			
			$this->assign('section', $section);
			$this->assign('cate', $this->section->getCate());			
			
			$this->display('add.tpl.php');
		}
	}
	public function actionsCate()
	{
		$cate = $this->section->getCateList();
		$this->assign('cate', $cate);
	}
	public function actionsAddcate()
	{
		if (Http::get('do')=='add'){
			$name=Http::get('name');
			$sort=Http::get('sort');
			if (empty($name)){
				die(json_encode(array('status'=>0,'html'=>'名称不能为空')));
			}else {
				
				if($this->section->addCate($name,$sort)){
					die(json_encode(array('status'=>1,'html'=>'添加成功')));
				}else{
					die(json_encode(array('status'=>0,'html'=>'添加失败')));					
				}
			}
			
		}
		$this->assign('cate', '');
	}
	public function actionsCatemodify()
	{
		$cateId = Http::get('id');
		if (Http::get('do')=='update'){
			$name=Http::get('name');
			$sort=Http::get('sort');
			if (empty($name)){
				die(json_encode(array('status'=>0,'html'=>'名称不能为空')));
			}else {
				
				if($this->section->updateCate($cateId,$name,$sort)){
					die(json_encode(array('status'=>1,'html'=>'修改成功')));
				}else{
					die(json_encode(array('status'=>0,'html'=>'修改失败')));					
				}
			}
		}
		
		
		$cate = $this->section->getCate($cateId);
		$this->assign('cate', $cate);
		$this->display('addcate.tpl.php');	
	}
	public function actionsCatedel()
	{		
		if($this->section->delCate(Http::get('id')))
		{
			echo '删除成功！';
		}else{
			echo '删除失败！';
		}
		die();
	}
	
	public function actionsEditsectioncontent()
	{
		$sectionId = Http::get('sectionid');
		$rs = $this->section->getSectiondata($sectionId);
		$this->assign('rs', $rs);
		$this->assign('section', $this->section->getSection($sectionId));
	}
	public function actionsAddSectiondata()
	{
		$sectionid = Http::get('sectionid');
		if (Http::get('do')=='add'){
			$title=Http::get('title');
			$url=Http::get('url');
			$sorts=Http::get('sorts');
			$thumb=Http::get('thumb');
			$description=Http::get('description');
			
			
			if (empty($title)){
				die(json_encode(array('status'=>0,'html'=>'名称不能为空')));
			}else {
				$data = array('sectionid'=>$sectionid,'title'=>$title,'url'=>$url,'sorts'=>$sorts,'thumb'=>$thumb,'description'=>$description);
				if($this->section->addSectiondata($data)){
					die(json_encode(array('status'=>1,'html'=>'添加成功')));
				}else{
					die(json_encode(array('status'=>0,'html'=>'添加失败')));					
				}
			}
			
		}
		$this->assign('data', '');
	}
	public function actionsDatamodify()
	{
		$id = Http::get('id');
		if (Http::get('do')=='update'){
			$title=Http::get('title');
			$url=Http::get('url');
			$sorts=Http::get('sorts');
			$thumb=Http::get('thumb');
			$description=Http::get('description');
			
			
			if (empty($title)){
				die(json_encode(array('status'=>0,'html'=>'名称不能为空')));
			}else {
				$data = array('title'=>$title,'url'=>$url,'sorts'=>$sorts,'thumb'=>$thumb,'description'=>$description);
				if($this->section->updateSectiondata($id,$data)){
					die(json_encode(array('status'=>1,'html'=>'添加成功')));
				}else{
					die(json_encode(array('status'=>0,'html'=>'添加失败')));					
				}
			}
			
		}
		$data = $this->section->getSectiondataRow($id);
		$this->assign('data', $data);
		
		$this->display('addsectiondata.tpl.php');
	}
	public function actionsDatadel()
	{
			
		if($this->section->delData(Http::get('id')))
		{
			echo '删除成功！';
		}else{
			echo '删除失败！';
		}
		die();
	}
}#classEnd